package com.shqcjd.sinopecdemomobile.ui.activity.problem;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.shqcjd.sinopecdemomobile.R;
import com.shqcjd.sinopecdemomobile.model.pojo.UploadFileRet;
import com.shqcjd.sinopecdemomobile.ui.activity.preview.PreImageActivity;
import com.shqcjd.sinopecdemomobile.ui.activity.preview.VideosActivity;
import com.shqcjd.sinopecdemomobile.ui.adapter.MoreProblemItemImgAdapter;
import com.shqcjd.sinopecdemomobile.ui.base.BaseActivity;
import com.shqcjd.sinopecdemomobile.ui.base.BasePresenter;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 问题反馈-更多文件列表
 */
public class ProblemMoreFileActivity extends BaseActivity {


    @BindView(R.id.iv_toolbar_back)
    ImageView ivToolbarBack;
    @BindView(R.id.tv_toolbar_center)
    TextView tvToolbarCenter;
    @BindView(R.id.rv_file_list)
    RecyclerView rvFileList;
    private List<UploadFileRet> fileList;
    private Context mContext;

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_problem_more_file;
    }

    @Override
    public void initView() {
        super.initView();
        mContext = this;
        tvToolbarCenter.setText("更多");
        fileList = (List<UploadFileRet>) getIntent().getSerializableExtra("list");

        MoreProblemItemImgAdapter problemImgAdapter = new MoreProblemItemImgAdapter(fileList, mContext);
        rvFileList.setLayoutManager(new GridLayoutManager(mContext,3));
        rvFileList.setAdapter(problemImgAdapter);
        problemImgAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                UploadFileRet item = (UploadFileRet) adapter.getItem(position);
                if(item.extension.equals(".mp4")){
                    Intent it = new Intent(mContext, VideosActivity.class);
                    it.putExtra("url", item.url);
                    it.putExtra("name", "视频详情");
                    startActivity(it);
                }else{
                    Intent it = new Intent(mContext, PreImageActivity.class);
                    it.putExtra("url", item.url);
                    it.putExtra("name", "图片详情");
                    startActivity(it);
                }
            }
        });
    }

    @OnClick(R.id.iv_toolbar_back)
    public void onViewClicked() {
        finish();
    }
}
